library(readr)
library(tidyverse)
library(forcats)
library(plotly)
library(knitr, warn.conflicts = FALSE, quietly=TRUE)
library(RColorBrewer)
library(stringr)
library(dygraphs)
library(xts)
myPalette <- brewer.pal(8, "YlGn")
vgsales <- read_csv("vgsales.csv")

Anzahl der Videospiele aufgelistet nach Platform

grouped <- vgsales  %>% 
  group_by(Platform) %>% 
  summarize(Anzahl =n()) 

ordered <- grouped[order(grouped$Anzahl), decreasing = FALSE]
ordered$Platform <- as_factor(ordered$Platform)


ax <- list(
  title = "Publisher"
)

ay <- list(
  title = "Anzahl"
)
ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Platform,Anzahl, .desc="true"),
           y=~Anzahl,
           name="Game Amount by Platform") %>% 
  layout(title="Game Amount by Platform",
         xaxis = ax,
         yaxis = ay
         
         )

Ältere Plattformen/spiele haben mehr verkäufe bzw Wie hat sich die Anzahl der verkäufe im laufe der jahre entwickelt? (Gefiltert auf Plattformen mit mindestens 50 mio in Sales)

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

Welche Plattform ist die beste und unterscheidet sich diese nach Region?

grouped <- vgsales  %>% 
  group_by(Platform) %>% 
  summarize(sum(Global_Sales))  %>%
rename(
    Global_Sales = "sum(Global_Sales)"
    )
grouped$Global_Sales<-as_vector(grouped$Global_Sales)
ordered <- grouped[order(grouped$Global_Sales), decreasing = FALSE]
ordered$Platform <- as_factor(ordered$Platform)


ax <- list(
  title = "Platform"
)

ay <- list(
  title = "Global Sales (in mio)"

)


ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Platform,Global_Sales, .desc="true"),
           y=~Global_Sales,
           name="Sales Amount by Platform") %>% 
  layout(title="Sales Amount by Platform",
         xaxis = ax,
         yaxis = ay
         )

● Gibt es Unterschiede in den Regionen/hängt das mit der Anzahl der Einwohner der Region zusammen? (Asian>US>EU)

grouped <- vgsales  %>% 
  group_by(Platform) %>% 
  summarize(sum(EU_Sales))  %>%
rename(
    Global_Sales = "sum(EU_Sales)"
    )
grouped$Global_Sales<-as_vector(grouped$Global_Sales)
ordered <- grouped[order(grouped$Global_Sales), decreasing = FALSE]
ordered$Platform <- as_factor(ordered$Platform)


ax <- list(
  title = "Platform"
)

ay <- list(
  title = "EU Sales (in mio)"

)


ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Platform,Global_Sales, .desc="true"),
           y=~Global_Sales,
           name="EU Sales Amount by Platform") %>% 
  layout(title="EU Sales Amount by Platform",
         xaxis = ax,
         yaxis = ay
         )
ordered%>%
  plot_ly() %>% 
  add_pie(values =~Global_Sales,labels=~Platform,textinfo='label+percent',
           name="EU Sales Amount by Publisher") %>% 
  layout(title="EU Sales Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         )
grouped <- vgsales  %>% 
  group_by(Platform) %>% 
  summarize(sum(NA_Sales))  %>%
rename(
    Global_Sales = "sum(NA_Sales)"
    )
grouped$Global_Sales<-as_vector(grouped$Global_Sales)
ordered <- grouped[order(grouped$Global_Sales), decreasing = FALSE]
ordered$Platform <- as_factor(ordered$Platform)


ax <- list(
  title = "Platform"
)

ay <- list(
  title = "NA Sales (in mio)"

)


ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Platform,Global_Sales, .desc="true"),
           y=~Global_Sales,
           name="NA Sales Amount by Platform") %>% 
  layout(title="NA Sales Amount by Platform",
         xaxis = ax,
         yaxis = ay
         )
ordered%>%
  plot_ly() %>% 
  add_pie(values =~Global_Sales,labels=~Platform,textinfo='label+percent',
           name="NA Sales Amount by Publisher") %>% 
  layout(title="NA Sales Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         )
grouped <- vgsales  %>% 
  group_by(Platform) %>% 
  summarize(sum(JP_Sales))  %>%
rename(
    Global_Sales = "sum(JP_Sales)"
    )
grouped$Global_Sales<-as_vector(grouped$Global_Sales)
ordered <- grouped[order(grouped$Global_Sales), decreasing = FALSE]
ordered$Platform <- as_factor(ordered$Platform)


ax <- list(
  title = "Platform"
)

ay <- list(
  title = "JP Sales (in mio)"

)


ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Platform,Global_Sales, .desc="true"),
           y=~Global_Sales,
           name="JP Sales Amount by Platform") %>% 
  layout(title="JP Sales Amount by Platform",
         xaxis = ax,
         yaxis = ay
         )
ordered%>%
  plot_ly() %>% 
  add_pie(values =~Global_Sales,labels=~Platform,textinfo='label+percent',
           name="JP Sales Amount by Publisher") %>% 
  layout(title="JP Sales Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         )

Bestimmte Entwickler/Publisher häufen sich (Nintendo/EA)

Top Publisher nach Anzahl der Games

grouped <- vgsales  %>% 
  group_by(Publisher) %>% 
  summarize(Anzahl =n()) %>%  
  filter(Anzahl>100) %>% filter(Publisher!="Unknown")

ordered <- grouped[order(grouped$Anzahl), decreasing = FALSE]
ordered$Publisher <-str_remove_all(ordered$Publisher, "Entertainment")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Interactive")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Studios")
ordered$Publisher <- as_factor(ordered$Publisher)


ax <- list(
  title = "Publisher"
)

ay <- list(
  title = "Anzahl"
)
ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Publisher,Anzahl, .desc="true"),
           y=~Anzahl,
           name="Game Amount by Publisher") %>% 
  layout(title="Game Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         
         )

Top Publisher nach Anzahl der Sales

grouped <- vgsales  %>% 
  group_by(Publisher) %>% 
  summarize(Anzahl =n(),sum(Global_Sales)) %>%
  filter(Anzahl>100) %>%
rename(
    Global_Sales = "sum(Global_Sales)"
    )
grouped$Global_Sales<-as_vector(grouped$Global_Sales)
ordered <- grouped[order(grouped$Global_Sales), decreasing = FALSE]
ordered$Publisher <-str_remove_all(ordered$Publisher, "Entertainment")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Interactive")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Studios")
ordered$Publisher <- as_factor(ordered$Publisher)


ax <- list(
  title = "Publisher"
)

ay <- list(
  title = "Global Sales (in mio)"

)


ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Publisher,Global_Sales, .desc="true"),
           y=~Global_Sales,
           name="Sales Amount by Publisher") %>% 
  layout(title="Sales Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         )

● Welche Spiele/Publisher/Genres in welchen Teilen der welt sich häufen (Nintendo in Asien, Shooter in US/EU)

grouped <- vgsales  %>% 
  group_by(Publisher) %>% 
  summarize(Anzahl =n(),sum(EU_Sales)) %>%
  filter(Anzahl>100) %>%
rename(
    Global_Sales = "sum(EU_Sales)"
    )
grouped$Global_Sales<-as_vector(grouped$Global_Sales)
ordered <- grouped[order(grouped$Global_Sales), decreasing = FALSE]
ordered$Publisher <-str_remove_all(ordered$Publisher, "Entertainment")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Interactive")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Studios")
ordered$Publisher <- as_factor(ordered$Publisher)


ax <- list(
  title = "Publisher"
)

ay <- list(
  title = "EU Sales (in mio)"

)

ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Publisher,Global_Sales, .desc="true"),
           y=~Global_Sales,
           name="EU Sales Amount by Publisher") %>% 
  layout(title="EU Sales Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         )
ordered%>%
  plot_ly() %>% 
  add_pie(values =~Global_Sales,labels=~Publisher,
           name="EU Sales Amount by Publisher") %>% 
  layout(title="EU Sales Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         )
grouped <- vgsales  %>% 
  group_by(Publisher) %>% 
  summarize(Anzahl =n(),sum(NA_Sales)) %>%
  filter(Anzahl>100) %>%
rename(
    Global_Sales = "sum(NA_Sales)"
    )
grouped$Global_Sales<-as_vector(grouped$Global_Sales)
ordered <- grouped[order(grouped$Global_Sales), decreasing = FALSE]
ordered$Publisher <-str_remove_all(ordered$Publisher, "Entertainment")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Interactive")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Studios")
ordered$Publisher <- as_factor(ordered$Publisher)


ax <- list(
  title = "Publisher"
)

ay <- list(
  title = "NA Sales (in mio)"

)

ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Publisher,Global_Sales, .desc="true"),
           y=~Global_Sales,
           name="NA Sales Amount by Publisher") %>% 
  layout(title="NA Sales Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         )
ordered%>%
  plot_ly() %>% 
  add_pie(values =~Global_Sales,labels=~Publisher,textinfo='label+percent',
           name="NA Sales Amount by Publisher") %>% 
  layout(title="NA Sales Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         )
grouped <- vgsales  %>% 
  group_by(Publisher) %>% 
  summarize(Anzahl =n(),sum(JP_Sales)) %>%
  filter(Anzahl>100) %>%
rename(
    Global_Sales = "sum(JP_Sales)"
    )
grouped$Global_Sales<-as_vector(grouped$Global_Sales)
ordered <- grouped[order(grouped$Global_Sales), decreasing = FALSE]
ordered$Publisher <-str_remove_all(ordered$Publisher, "Entertainment")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Interactive")
ordered$Publisher <-str_remove_all(ordered$Publisher, "Studios")
ordered$Publisher <- as_factor(ordered$Publisher)


ax <- list(
  title = "Publisher"
)

ay <- list(
  title = "JP Sales (in mio)"

)

ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Publisher,Global_Sales, .desc="true"),
           y=~Global_Sales,
           name="JP Sales Amount by Publisher") %>% 
  layout(title="JP Sales Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         )
ordered%>%
  plot_ly() %>% 
  add_pie(values =~Global_Sales,labels=~Publisher,
           name="JP Sales Amount by Publisher") %>% 
  layout(title="JP Sales Amount by Publisher",
         xaxis = ax,
         yaxis = ay
         )
grouped <- vgsales  %>% 
  group_by(Genre) %>% 
  summarize(Anzahl =n())

grouped$Anzahl<-as_vector(grouped$Anzahl)
ordered <- grouped[order(grouped$Anzahl), decreasing = FALSE]
ordered$Genre <- as_factor(ordered$Genre)


ax <- list(
  title = "Genre"
)

ay <- list(
  title = "Anzahl"

)

ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Genre,Anzahl, .desc="true"),
           y=~Anzahl,
           name="Amount by Genre") %>% 
  layout(title="Amount by Genre",
         xaxis = ax,
         yaxis = ay
         )
ordered%>%
  plot_ly() %>% 
  add_pie(values =~Anzahl,labels=~Genre,
           name="Amount by Genre") %>% 
  layout(title="Amount by Genre",
         xaxis = ax,
         yaxis = ay
         )
grouped <- vgsales  %>% 
  group_by(Genre) %>% 
  summarize(sum(Global_Sales))  %>%
rename(
    Global_Sales = "sum(Global_Sales)"
    )
grouped$Global_Sales<-as_vector(grouped$Global_Sales)
ordered <- grouped[order(grouped$Global_Sales), decreasing = FALSE]

ax <- list(
  title = "Genre"
)

ay <- list(
  title = "Sales"

)

ordered%>%
  plot_ly() %>% 
  add_bars(x=~fct_reorder(Genre,Global_Sales, .desc="true"),
           y=~Global_Sales,
           name="Sales by Genre") %>% 
  layout(title="Sales by Genre",
         xaxis = ax,
         yaxis = ay
         )
ordered%>%
  plot_ly() %>% 
  add_pie(values =~Global_Sales,labels=~Genre,
           name="Sales by Genre") %>% 
  layout(title="Sales by Genre",
         xaxis = ax,
         yaxis = ay
        )

● Genrenentwicklung über die Jahre

grouped <- vgsales  %>%                                 
  group_by(Year, Genre) %>%
  dplyr::summarize(Anzahl =n()) %>% filter(Year!='N/A')%>%filter(Year!=2020) %>% filter(Year!='2017') %>%
  as.data.frame()


filtered <- grouped %>% select(Year,Genre,Anzahl)
ax <- list(
  title = "Year"
)

ay <- list(
  title = "Anzahl"

)

filtered %>%
plot_ly() %>% 
  add_lines(x=~Year,
           y=~Anzahl, color=~Genre)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
filtered %>%
plot_ly(x = ~Year, y = ~Anzahl, type = 'scatter', mode = 'none', fill = 'tozeroy',color = ~Genre)%>% 
  layout(title="Amount by Genre from 1980-2016",
         xaxis = ax,
         yaxis = ay
         )
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
filtered %>%
plot_ly(x = ~Year, y = ~Anzahl, type = 'scatter', mode = 'none', stackgroup = 'one',color = ~Genre)%>% 
  layout(title="Amount by Genre from 1980-2016",
         xaxis = ax,
         yaxis = ay
         )
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
ay <- list(
  title = "Percent %"

)

filtered %>%
plot_ly(x = ~Year, y = ~Anzahl, type = 'scatter', mode = 'none', stackgroup = 'one',groupnorm = 'percent',color = ~Genre)%>% 
  layout(title="Marketamount genreshift in % from 1980-2016",
         xaxis = ax,
         yaxis = ay
         )
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

● Gibt es Statistische zusammenhänge zwischen einzelnen Faktoren e.g. Genre -> Sales

grouped <- vgsales  %>%                                 
  group_by(Year, Genre) %>%
  dplyr::summarize(gr_sum = sum(Global_Sales)) %>% filter(Year!='N/A')%>%filter(Year!=2020) %>% filter(Year!='2017') %>%
  as.data.frame()


filtered <- grouped %>% select(Year,Genre,gr_sum)

ax <- list(
  title = "Year"
)

ay <- list(
  title = "Global_Sales"

)

filtered %>%
plot_ly() %>% 
  add_lines(x=~Year,
           y=~gr_sum, color=~Genre) %>% 
  layout(title="Sales by Genre from 1980-2016",
         xaxis = ax,
         yaxis = ay
         )
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
filtered %>%
plot_ly(x = ~Year, y = ~gr_sum, type = 'scatter', mode = 'none', fill = 'tozeroy',color = ~Genre) %>% 
  layout(title="Sales by Genre from 1980-2016",
         xaxis = ax,
         yaxis = ay
         )
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
filtered %>%
plot_ly(x = ~Year, y = ~gr_sum, type = 'scatter', mode = 'none', stackgroup = 'one',color = ~Genre)%>% 
  layout(title="Sales by Genre from 1980-2016",
         xaxis = ax,
         yaxis = ay
         )
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
ay <- list(
  title = "Percent %"

)
filtered %>%
plot_ly(x = ~Year, y = ~gr_sum, type = 'scatter', mode = 'none', stackgroup = 'one',groupnorm = 'percent',color = ~Genre)%>% 
  layout(title="Marketshare genreshift in % from 1980-2016",
         xaxis = ax,
         yaxis = ay
         )
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

● Welche Jahre sind die besten in der Anzahl der releasten games

grouped <- vgsales  %>%                                 
  group_by(Year) %>%
  dplyr::summarize(Anzahl =n()) %>% filter(Year!='N/A')%>%filter(Year!=2020) %>% filter(Year!='2017') %>%
  as.data.frame()


filtered <- grouped %>% select(Year,Anzahl)

ax <- list(
  title = "Year"
)

ay <- list(
  title = "Amount"

)

filtered %>%
plot_ly(x = ~Year, y = ~Anzahl, type = 'scatter', mode = 'lines', fill = 'tozeroy') %>% 
  layout(title="Game Amount from 1980-2016",
         xaxis = ax,
         yaxis = ay
         )

● Welche Jahre sind die besten in Anzahl Sales pro game (neuer = besser?)

grouped <- vgsales  %>%                                 
  group_by(Year) %>%
  dplyr::summarize(gr_sum = sum(Global_Sales)/n()) %>% filter(Year!='N/A')%>%filter(Year!=2020) %>% filter(Year!='2017') %>%
  as.data.frame()


filtered <- grouped %>% select(Year,gr_sum)

ax <- list(
  title = "Year"
)

ay <- list(
  title = "Sales Per Game (in mio)"

)

filtered %>%
plot_ly(x = ~Year, y = ~gr_sum, type = 'scatter', mode = 'lines', fill = 'tozeroy') %>% 
  layout(title="Sales per Game from 1980-2016",
         xaxis = ax,
         yaxis = ay
         )
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors